package laf.socf.simulator.sensors;

import laf.socf.simulator.SensorServer;
import laf.socf.simulator.gui.Robot;
import org.freedesktop.dbus.DBusInterface;

/**
 *
 * @author laf
 */
public class Compass implements Sensor, DBusInterface {

    private Robot robot;
    private int count;
    
    public Compass() throws Exception {

    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public boolean isRemote() {
        return true;
    }
    
    public Compass(Robot robot, int count) throws Exception {
        this.robot = robot;
        this.count = count;
        init();
    }

    public void init() throws Exception {
        SensorServer.getInstance().exportObject("/server/Compass" + this.count,
               this);
    }

    public String getSensorName() {
        return "Compass";
    }

    public void startSensor() {

    }

    public void stopSensor() {

    }

    public double getDirection() {
        Robot.DIR dir = robot.getCurrentDir();
        if (dir == Robot.DIR.UP) {
            return 0;
        } else if (dir == Robot.DIR.LEFT) {
            return 270;
        } else if (dir == Robot.DIR.RIGHT) {
            return 90;
        } else if (dir == Robot.DIR.DOWN) {
            return 180;
        }
        return 0;
    }

}
